// pages/jubao/jubao.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    input:0,//鼠标聚焦
    report_content:'',  //举报内容
    reported_user_id:null,
    type:null,
    xx_id:null,
    xx_content:'',
  },

  //鼠标聚焦
  focus:function(){
    this.setData({
      input:1
    })
  },

  //鼠标移开
  blur:function(){
    this.setData({
      input:0
    })
  },

  repContent:function(e){
    var that = this
    that.setData({
      report_content:e.detail.value
    })
 
  },

  //举报
  report:function(){
    var that = this
    if(that.data.report_content){
      
      if(getApp().globalData.userInfo.user_id!=undefined){
        wx.showLoading({
          title: '加载中...',
        })
        wx.request({ //后端接口获取回答同一问题的文件
          url: 'https://www.cerywxr.com/treehole/index.php/Home/report/do_report',
          method: "POST", //请求方式,
          header: {
            'content-type': 'application/x-www-form-urlencoded' //POST提交数据方式
          },
          data: {
            report_user_id:getApp().globalData.userInfo.user_id,
            reported_user_id: that.data.reported_user_id,
            report_content:that.data.report_content,
            type:that.data.type,
            xx_id: that.data.xx_id,
            xx_content:that.data.xx_content,
          },
          success(res) {
            console.log(res.data)
            if(res.data.error_code == 0){
              wx.showModal({
                title: '提示!',
                content: '提交成功',
                showCancel: false,
                success(res) {
                  wx.navigateBack({
                    delta: 1
                  })
                 }
              })
              
            }else if(res.data.error_code == 2){
              wx.showModal({
                title: '提示!',
                content: '请登录后使用小程序',
                showCancel: false,
                success(res) { }
              })
            }else if(res.data.error_code == 3){
              wx.showModal({
                title: '提示!',
                content: '该问题\文件\评论不存在',
                showCancel: false,
                success(res) { }
              })
            }else{
              console.log('report页面错误',res.data)
            }
          },fail:function(){
            wx.showModal({
              title: '哎呀~!',
              content: '网络状态不佳呢！',
              showCancel: false,
              success(res) { }
            })
          },complete:function(){
            wx.hideLoading()
          }
        })
      }else{
        wx.showModal({
          title: '提示!',
          content: '请授权后再使用小程序',
          showCancel: false,
          success(res) { 
            wx.navigateTo({
              url: '/pages/login/login'
            })
          }
        })
      }
     
    }else{
      wx.showModal({
        title: '提示!',
        content: '举报原因不能为空',
        showCancel: false,
        success(res) { }
      })
    }
   
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    that.setData({
      reported_user_id:options.reported_user_id,
      type:options.type,
      xx_id:options.xx_id,
      xx_content:options.xx_content,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})